package com.haircut.project.controller.category;

import com.haircut.project.service.category.ICategoryService;
import com.haircut.project.vo.catetory.CateTreeVo;
import com.haircut.project.vo.catetory.CategoryOptVo;
import com.haircut.project.vo.catetory.CategoryTreeVo;
import com.haircut.project.vo.catetory.CategoryVo;
import com.modular.result.RspMessage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/b/project/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询分类列表
     * @return
     */
    @ApiOperation(value = "查询分类列表")
    @GetMapping("findAll")
    public RspMessage<List<CategoryTreeVo>> findAll(){
        return RspMessage.success(categoryService.findAll());
    }
    /**
     * 新增分类
     */
    @ApiOperation(value = "新增分类")
    @PostMapping("saveCate")
    public RspMessage<Void> saveCate(@Validated @RequestBody CategoryOptVo reqVo){
        categoryService.saveCategory(reqVo);
        return RspMessage.success();
    }
    /**
     * 修改分类
     */
    @ApiOperation(value = "修改分类")
    @PostMapping("modifyCate")
    public RspMessage<Void> modifyCate(@Validated @RequestBody CategoryOptVo reqVo){
        categoryService.modifyCategory(reqVo);
        return RspMessage.success();
    }
    /**
     * 删除分类
     */
    @ApiOperation(value = "删除分类")
    @GetMapping("delCategory")
    public RspMessage<Void> delCategory(@ApiParam("分类id") @RequestParam("cateId") String cateId){
        categoryService.delCategory(cateId);
        return RspMessage.success();
    }

    /**
     * 根据分类查询下级分类
     */
    @ApiOperation(value = "根据分类查询下级分类")
    @GetMapping("findParentId")
    public RspMessage<List<CategoryVo>> findParentId(@ApiParam("上级分类id") @RequestParam("parentId") String parentId){
        return RspMessage.success(categoryService.findParentId(parentId));
    }

    /**
     * 查询分类列表
     * @return
     */
    @ApiOperation(value = "查询分类列表")
    @GetMapping("findTree")
    public RspMessage<List<CateTreeVo>> findTree(){
        return RspMessage.success(categoryService.findTree());
    }
}
